home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD-ROM Today - The Disc! 5
/
CD-ROM Today - The Disc (Issue 5)(November 1994).ISO
/
mac
/
Mac shareware
/
Education
/
RLaB
/
rlib
/
std.r
< prev
next >
Wrap
Text File
|
1994-09-21
|
752b
|
31 lines
//-------------------------------------------------------------------//
// Syntax: std ( A )
// Description:
// Compute the Standard Deviation. For a vector (row-matrix), std()
// returns the standard deviation. For a MxN matrix, std() returns a
// row-matrix containing the standard deviation of each column.
// See Also: mean, rand, srand
//-------------------------------------------------------------------//
std = function(x)
{
local(i, m, s);
if(class(x) != "num") { error("std() requires NUMERICAL input"); }
m = x.nr;
if( m == 1 )
{
return sqrt( sum( (x - mean(x)) .^ 2 ) / (x.nc - 1) );
else
for( i in 1:x.nc) {
s[i] = sqrt( sum( (x[;i] - mean(x[;i])) .^ 2 ) / (x.nr - 1) );
}
return s;
}
};